package com.ruoyi.zsyh.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zsyh.domain.ZsyhUserHelp;
import com.ruoyi.zsyh.service.IZsyhUserHelpService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 帮助中心Controller
 * 
 * @author yuexl
 * @date 2022-02-25
 */
@Controller
@RequestMapping("/zsyh/userHelp")
public class ZsyhUserHelpController extends BaseController
{
    private String prefix = "zsyh/userHelp";

    @Autowired
    private IZsyhUserHelpService zsyhUserHelpService;

    @RequiresPermissions("zsyh:userHelp:view")
    @GetMapping()
    public String userHelp()
    {
        return prefix + "/userHelp";
    }

    /**
     * 查询帮助中心列表
     */
    @RequiresPermissions("zsyh:userHelp:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZsyhUserHelp zsyhUserHelp)
    {
        startPage();
        List<ZsyhUserHelp> list = zsyhUserHelpService.selectZsyhUserHelpList(zsyhUserHelp);
        return getDataTable(list);
    }

    /**
     * 导出帮助中心列表
     */
    @RequiresPermissions("zsyh:userHelp:export")
    @Log(title = "帮助中心", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZsyhUserHelp zsyhUserHelp)
    {
        List<ZsyhUserHelp> list = zsyhUserHelpService.selectZsyhUserHelpList(zsyhUserHelp);
        ExcelUtil<ZsyhUserHelp> util = new ExcelUtil<ZsyhUserHelp>(ZsyhUserHelp.class);
        return util.exportExcel(list, "帮助中心数据");
    }

    /**
     * 新增帮助中心
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存帮助中心
     */
    @RequiresPermissions("zsyh:userHelp:add")
    @Log(title = "帮助中心", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZsyhUserHelp zsyhUserHelp)
    {
        return toAjax(zsyhUserHelpService.insertZsyhUserHelp(zsyhUserHelp));
    }

    /**
     * 修改帮助中心
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhUserHelp zsyhUserHelp = zsyhUserHelpService.selectZsyhUserHelpById(id);
        mmap.put("zsyhUserHelp", zsyhUserHelp);
        return prefix + "/edit";
    }

    /**
     * 修改保存帮助中心
     */
    @RequiresPermissions("zsyh:userHelp:edit")
    @Log(title = "帮助中心", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZsyhUserHelp zsyhUserHelp)
    {
        return toAjax(zsyhUserHelpService.updateZsyhUserHelp(zsyhUserHelp));
    }

    /**
     * 删除帮助中心
     */
    @RequiresPermissions("zsyh:userHelp:remove")
    @Log(title = "帮助中心", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zsyhUserHelpService.deleteZsyhUserHelpByIds(ids));
    }
}
